<?php

namespace app\controller\index;

use app\result\SettingResult;
use app\result\UserSettingResult;
use think\App;

class Setting extends BaseIndex
{
    protected $unauthorized = ['base_info'];

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->objResult = new UserSettingResult();
    }

    //详情
    public function get()
    {
        $key = $this->param['key'] ?? '';
        if (!$key) {
            data_return('参数错误', 1);
        }
        switch ($key) {
            case 'diy_action':
                $res = $this->objResult->get_diy_action_config($this->user_id);
                break;
            default:
                data_return('暂不支持', 1);
        }
        data_exit_json($res);
    }

    public function update()
    {
        $key = $this->param['key'] ?? '';
        if (!$key) {
            data_return('参数错误', 1);
        }
        $list = $this->param['list'] ?? [];
        if (!is_array($list) || !count($list)) {
            data_return('配置项不存在', 1);
        }
        switch ($key) {
            case 'diy_action':
                $res = $this->objResult->setting_set($this->user_id, $this->param, 'diy_action_config');
                break;
            default:
                data_return('暂不支持', 1);
        }
        data_exit_json($res);
    }

    public function base_info()
    {
        $check = (new SettingResult())->base_info($this->param);
        data_exit_json($check);
    }

}
